import axios from 'axios'
import { Message } from 'element-ui'
import NproGress from 'nprogress'
import WhiteList from './list.json'
import 'nprogress/nprogress.css'

// 白名单
// let WhiteList = ["/user/login"]


// 请求拦截
axios.interceptors.request.use((config) => {
    // 开启加载中
    NproGress.start()
    const token = sessionStorage.getItem('token')? sessionStorage.getItem('token'): ''
    config.headers.Authorization = token
    return config
})

// 响应拦截
axios.interceptors.response.use((data) => {
    // 关闭加载过程
    NproGress.done()
    // 判断当前地址是否存在白名单中
    let flag = WhiteList.includes(data.config.url)
    if (flag) {
        Message.success(data.data.msg)
    }
    return data.data
})

export default axios